//- Copyright (C) 2018-2022 Chatopera Inc, <https://www.chatopera.com>
//- 
//- Licensed under the Apache License, Version 2.0 (the "License");
//- you may not use this file except in compliance with the License.
//- You may obtain a copy of the License at
//- 
//-  http://www.apache.org/licenses/LICENSE-2.0
//- 
//-  Unless required by applicable law or agreed to in writing, software
//- distributed under the License is distributed on an "AS IS" BASIS,
//-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//- See the License for the specific language governing permissions and
//- limitations under the License.
extends /apps/include/layout.pug

include /mixins/client.mixin.pug

block append head
    script(src="/js/CSKeFu_Rest_Request.v1.js")
    script(src="/js/CSKeFu_Agent_Invite.v1.js")

block content
    .layui-side.layui-bg-black.layui-left-black
        .layui-side-scroll
            include include/left
    .layui-body
        .layui-side-scroll
            .row
                .col-lg-12
                    h1.site-h1(style="border-top:1px solid #e6e6e6;height:50px;")
                        span.ukefu-bt
                            i.layui-icon.ukewo-btn(style="font-size:28px;") 
                            .ukefu-bt-text
                                .ukefu-bt-text-title(style="")
                                    | 当前在线用户列表
                                .ukefu-bt-text-content(style="margin-top: 0px;line-height: 20px;")
                                    | 在线的访客详细信息
                    table.layui-table(lay-skin="line", style="table-layout: fixed; word-break: break-all")
                        thead
                            tr.design-sortable-tr
                                th(width="15%") 用户名
                                th 终端
                                th 操作系统
                                th 浏览器
                                th 访问时间
                                th 停留时间
                                th 地域
                                th 邀请次数
                                th(width="110px") 操作
                        tbody
                            if onlineUserList && onlineUserList.content && !onlineUserList.content.empty()
                                for onlineuser in onlineUserList.content
                                    tr.tdHasContorllor.design-dropable-td
                                        td(title=onlineuser.username + (onlineuser.contacts ? `(${onlineuser.contacts.name})` : ""), style="text-overflow: ellipsis;white-space: nowrap;overflow: hidden")
                                            a(href="/service/online/index.html?userid=" + onlineuser.userid)= onlineuser.username
                                        td.ukefu-online-client
                                            +device(onlineuser.mobile)
                                        td.ukefu-online-client
                                            +opersystem(onlineuser.opersystem)
                                        td= onlineuser.browser
                                        td= pugHelper.formatDate('yyyy-MM-dd HH:mm:ss', onlineuser.createtime)
                                        td.minSize #{pugHelper.padRight(onlineuser.betweentime / (1000 * 60 * 60), '00')}:#{pugHelper.padRight((onlineuser.betweentime % (1000 * 60 * 60)) / (1000 * 60), "00")}:#{pugHelper.padRight((onlineuser.betweentime % (1000 * 60)) / (1000), "00")}
                                        td= onlineuser.region
                                        td= onlineuser.invitetimes
                                        td
                                            if onlineuser.invitestatus == 'invite'
                                                small.layui-btn.layui-btn-mini.layui-btn-warm(title="访客已邀请") 已邀请
                                            else if onlineuser.invitestatus == 'inserv'
                                                small.layui-btn.layui-btn-mini(title="对话中") 对话中
                                            else if onlineuser.invitestatus == 'refuse'
                                                a.layui-btn.layui-btn-mini.layui-btn-danger(href="javascript:;", name="#{onlineuser.id}", title="访客已拒绝邀请", onclick="sendInvitationToOnlineUser('#{onlineuser.id}', false)") 再次邀请
                                            else
                                                a.layui-btn.layui-btn-mini.layui-btn-normal(href="javascript:;", name="#{onlineuser.id}", title="邀请访客", onclick="sendInvitationToOnlineUser('#{onlineuser.id}', true)") 邀请
                                            a.layui-btn.layui-btn-mini.layui-btn-normal(href="/service/trace.html?sessionid=#{onlineuser.sessionid}&userid=#{onlineuser.id}", title="查看访客轨迹", data-toggle="ajax", data-width="1050") 轨迹
                            else
                                tr
                                    td(colspan="9", style="height:400px;")
                                        .ukefu-empty(style="background: none")
                                            i.layui-icon 
                                            div(style="") 还没有在线访客记录

            .row(style="padding:5px;")
                #page.col-lg-12(style="text-align:center;")

    script.
        layui.use(['laypage', 'layer'], function () {
            var laypage = layui.laypage, layer = layui.layer;

            laypage({
                cont: 'page',
                pages: #{onlineUserList ? onlineUserList.totalPages : 0}, //总页数
                curr: #{onlineUserList ? onlineUserList.number + 1 : 0},
                groups: 5, //连续显示分页数
                jump: function (data, first) {
                    if (!first) {
                        location.href = "/apps/onlineuser.html?p=" + data.curr;
                    }
                }
            });
        });

        

